/**
 * 退单(表格数据获取) obj 表格对象
 */
function abandon(obj) {
    var data = getChecked(obj);
    console.log(data);
    if ("" == data || data.length == 0) {
        dggui.dialog.errors("请至少选择一条数据！", 3000);
        return;
    }
    /*    else if (data.length > 10) {
            dggui.dialog.errors("只能一条数据！", 3000);
        }*/
    else {
        var ids = new Array();
        data.forEach(function (e) {
            if (null != e.id && '' != e.id) {
                ids.push(e.id.toString());
            }
        });
        abandonGeneral(ids, obj);
    }
}

/**
 * 退单 ids 生成订单id集合
 */
function abandonGeneral(ids, obj) {
    dggui.dialog.loading();
    $.ajax({
        url: sysInfo.basePath + "/rzsc/processing_order/abandonPage.html",
        success: function (html) {
            dggui.dialog.loading('close');
            if (html.msg != null) {
                dggui.dialog.loading('close');
                dggui.dialog.errors(res.msg);
            }
            index = dggui.dialog.open({
                content: html,
                area: '500px',
                title: '申请退单',
                yes: function (index, layero) {
                    if (verifyEmpty($("#applyReason"), '请选择申请理由') &&
                        verifyEmpty($("#auditorId"), '请选择审核人') &&
                        verifyRemark($("#abandon_reason_remark"), 1, 500, "请填写1-500字的备注信息")
                    ) {
                        var abandonParams = new Object();

                        abandonParams.applyReasonCode = $("#applyReason").val();
                        abandonParams.auditorId = $("#auditorId").val();
                        abandonParams.remark = $("#abandon_reason_remark").val();
                        abandonParams.ids = ids;
                        var params = JSON.stringify(abandonParams);
                        dggui.dialog.confire('确认执行此操作？', '操作提示', function () {
                            dggui.dialog.loading();
                            $.ajax({
                                url: sysInfo.basePath + "/rzsc/processing_order/abandon_reason_order.do",
                                data: {params: params},
                                success: function (res) {
                                    dggui.dialog.loading('close');
                                    if (res.code == 0) {
                                        dggui.dialog.succeed(res.msg);
                                        layer.close(index);
                                        reloadTable(obj, "reload");
                                    } else {
                                        dggui.dialog.errors(res.msg);
                                    }
                                }
                            });
                        })
                    }
                }
            })
        }
    })
}


/**
 * 废单(表格数据获取) obj  table对象
 */
function nullify(obj) {//退废单不做批量
    var data = getChecked(obj);
    if ("" == data || data.length == 0) {
        dggui.dialog.errors("请选择一条数据！", 3000);
        return;
    }
    /*
        else if (data.length > 1) {
            dggui.dialog.errors("只能一条数据！", 3000);
        }
    */
    else {
        var ids = new Array();
        data.forEach(function (e) {
            if (null != e.id && '' != e.id) {
                ids.push(e.id.toString());
            }
        });
        console.log(JSON.stringify(ids));
        nullifyGeneral(ids, obj);
    }
}

/**
 * 退回 obj  table对象
 */
function blackOrderPage(obj, scProductId) {
    var id = null;
    if (!isEmpty(obj)) {
        var ids = getChecked(obj);
        if (ids.length < 1) {
            dggui.dialog.errors('请选择一条数据！');
            return;
        }
        if (ids.length > 1) {
            dggui.dialog.errors('只能选择一条数据！！');
            return;
        }
        id = getIds(ids);
    } else {
        if (isEmpty(scProductId)) {
            dggui.dialog.errors('生产单ID不能为空！');
            return;
        }
        id = scProductId;
    }

    blackOrderAjaxSubmit(id, obj);
}

// 弹出退回页面
function blackOrderAjaxSubmit(id, obj) {
    dggui.dialog.loading();
    $.ajax({
        url: sysInfo.basePath + "/rzsc/processing_order/back_order.html",
        dataType: 'html',
        success: function (res) {
            dggui.dialog.loading('close');
            dggui.dialog.open({
                title: '订单退回',
                content: res,
                area: '30%',
                btn: ["确定", "取消"],
                yes: function (index) {
                    sureBlackOrder(id, obj, index);
                }, btn2: function () {
                }
            })
        }
    });
}

/**
 * 废单 ids 生成订单id集合 obj  table对象
 */
function nullifyGeneral(ids, obj) {
    dggui.dialog.loading();
    $.ajax({
        url: sysInfo.basePath + "/rzsc/processing_order/nullifyPage.html",
        success: function (html) {
            if (html.msg != null) {
                dggui.dialog.loading('close');
                dggui.dialog.errors(res.msg);
            }
            index = dggui.dialog.open({
                content: html,
                area: '500px',
                title: '申请废单',
                yes: function (index, layero) {
                    dggui.dialog.loading('close');
                    if (verifyEmpty($("#applyReason"), '请选择申请原因') &&
                        verifyEmpty($("#auditorId"), '请选择审核人') &&
                        verifyRemark($("#abandon_reason_remark"), 1, 500, "请填写1-500字的备注信息")
                    ) {
                        var abandonParams = new Object();
                        abandonParams.applyReasonCode = $("#applyReason").val();
                        abandonParams.auditorId = $("#auditorId").val();
                        abandonParams.remark = $("#abandon_reason_remark").val();
                        abandonParams.ids = ids;
                        var params = JSON.stringify(abandonParams);
                        dggui.dialog.confire('确认执行此操作？', '操作提示', function () {
                            dggui.dialog.loading();
                            $.ajax({
                                url: sysInfo.basePath + "/rzsc/processing_order/nullify_reason_order.do",
                                data: {params: params},
                                success: function (res) {
                                    dggui.dialog.loading('close');
                                    if (res.code == 0) {
                                        dggui.dialog.succeed(res.msg);
                                        layer.close(index);
                                        reloadTable(obj, "reload");
                                    } else {
                                        dggui.dialog.errors(res.msg);
                                    }
                                }
                            });

                        })

                    }
                }
            })
        }
    })
}


/**
 * 分配  obj  table对象
 */
function allocate(obj, scProductId) {
    var ids = [];
    if (!isEmpty(obj)) {
        var data = getChecked(obj);
        if ("" == data || data.length == 0) {
            dggui.dialog.errors("请至少选择一条数据！", 3000);
            return;
        }
        data.forEach(function (e) {
            ids.push(e.id.toString());
        });
    } else {
        if (isEmpty(scProductId)) {
            dggui.dialog.errors("生产单ID不能为空！", 3000);
            return;
        }
        ids.push(scProductId);
    }

    dggui.dialog.loading();
    $.ajax({
        url: sysInfo.basePath + "/rzsc/allocate/allot_scorder_page.html",
        success: function (html) {
            if (html.msg != null) {
                dggui.dialog.loading('close');
                dggui.dialog.errors(html.msg);
            }
            index = dggui.dialog.open({
                content: html,
                area: '500px',
                title: '分配',
                yes: function (index, layero) {
                    dggui.dialog.loading('close');
                    if (verifyEmpty($("#flowUserId"), '请选择流程人员')) {
                        var allocateParams = new Object();
                        allocateParams.flowUserId = $("#flowUserId").val();
                        allocateParams.ids = ids;
                        var params = JSON.stringify(allocateParams);
                        dggui.dialog.confire('确认执行此操作？', '操作提示', function () {
                            dggui.dialog.loading();
                            $.ajax({
                                url: sysInfo.basePath + "/rzsc/allocate/allocate_order.do",
                                data: {params: params},
                                success: function (res) {
                                    dggui.dialog.loading('close');
                                    if (res.code == 0) {
                                        dggui.dialog.succeed(res.msg);
                                        layer.close(index);
                                        reloadTable(obj, "reload");
                                    } else {
                                        dggui.dialog.errors(res.msg);
                                    }
                                }
                            });

                        })

                    }
                }
            })
        }
    })

}

/**
 * 暂缓 （表格数据获取)  obj  table对象
 */

function suspend(obj) {
    var data = getChecked(obj);
    if ("" == data || data.length == 0) {
        dggui.dialog.errors("请至少选择一条数据！", 3000);
        return;
    }
    /*   else if (data.length > 10) {
           dggui.dialog.errors("最多选择10条数据！", 3000);
       } */
    else {
        var ids = new Array();
        data.forEach(function (e) {
            ids.push(e.id.toString());
        });
        console.log(JSON.stringify(ids));
        suspendPage(ids, obj)
    }
}

/**
 * 暂缓  obj  table对象
 */
function suspendPage(ids, obj) {
    dggui.dialog.loading();
    $.ajax({
        url: sysInfo.basePath + "/rzsc/processing_order/suspendPage.html",
        success: function (html) {
            if (html.msg != null) {
                dggui.dialog.loading('close');
                dggui.dialog.errors(html.msg);
            }
            index = dggui.dialog.open({
                content: html,
                area: '500px',
                title: '暂缓',
                yes: function (index, layero) {
                    dggui.dialog.loading('close');
                    console.log(($("#suspendReason").val()));
                    if (verifyEmpty($("#suspendReason"), '请选择暂缓原因') &&
                        verifyRemark($("#suspendReason_reason_remark"), 1, 500, "请填写1-500字的备注信息")) {
                        var suspendParams = new Object();
                        suspendParams.suspendReasonCode = $("#suspendReason").val();
                        suspendParams.ids = ids;
                        suspendParams.remark = $("#suspendReason_reason_remark").val();
                        var params = JSON.stringify(suspendParams);
                        dggui.dialog.confire('确认执行此操作？', '操作提示', function () {
                            dggui.dialog.loading();

                            $.ajax({
                                url: sysInfo.basePath + "/rzsc/processing_order/suspend_reason_order.do",
                                data: {params: params},
                                success: function (res) {
                                    dggui.dialog.loading('close');
                                    if (res.code == 0) {
                                        dggui.dialog.succeed(res.msg);
                                        layer.close(index);
                                        reloadTable(obj, "reload");
                                    } else {
                                        dggui.dialog.errors(res.msg);
                                    }
                                }
                            });

                        })

                    }
                }
            })
        }
    })
}

/**
 * 跳转到销售主订单详情页面
 */
function openBusinessDetail(orderNo, orderId) {
    var type = 2;
    window.parent.updateTab('销售详情:' + orderNo, orfApiUrl + "/orf/order/orderDetailAudited.do?id=" + orderId + "&type=" + type);
}

//订单备注
function remarkOrder(id, obj) {
    dggui.dialog.loading();
    $.ajax({
        url: sysInfo.basePath + "/all_order/remark_index.html",
        dataType: 'html',
        data: {id: id},
        success: function (res) {
            dggui.dialog.loading('close');
            dggui.dialog.open({
                title: '备注',
                content: res,
                area: '500px',
                btn: ["确定", "取消"],
                yes: function (index) {
                    remarkUpdate(index, obj);
                }, btn2: function () {
                }
            })
        }
    });
}

//暂缓恢复办理
function hintLayerzh(table, scProductId) {
    var id = null;
    if (!isEmpty(table)) {
        var data = getChecked(table);
        if (data.length < 1) {
            dggui.dialog.errors('请至少选中一条生产订单！');
            return;
        }
        var ids = new Array();
        data.forEach(function (e) {
            ids.push(e.id.toString());
        });
        id = ids.toString();
    } else {
        id = scProductId;
    }
    if (isEmpty(id)) {
        dggui.dialog.errors('生产单ID为空！');
        return;
    }
    dggui.dialog.confire('<span style="color: #ff0000">注：确认恢复后，对应生产订单将进入生产办理中环节</span>', '恢复办理', function () {
        dggui.dialog.loading();
        $.ajax({
            url: sysInfo.basePath + '/all_order/restore_order_suspended.do',
            type: 'POST',
            dataType: 'JSON',
            data: {'id': id},
            success: function (data) {
                dggui.dialog.loading('close');
                if (data.code == 0) {
                    dggui.dialog.succeed('操作成功！');
                    //刷新列表
                    /*search($('#rejectedOrder'));*/
                    if (isEmpty(table)) {
                        window.location.reload();
                    } else {
                        reloadTable(table, "reloadFalse");
                    }
                } else {
                    dggui.dialog.errors(data.msg);
                }
            },
            error: function () {
                dggui.dialog.loading('close');
                dggui.dialog.errors('发生异常，请稍后再试！');
            }
        });
    });

}

/**
 * 生产订单打电话
 * @param orderId 生产主订单ID
 */
function callPhoneByProduction(obj, id) {
    var orderId = "";
    if (id) {
        orderId = id;
    } else {
        var ids = getChecked(obj);
        if (ids.length < 1) {
            dggui.dialog.errors('请选择一条数据！');
            return;
        }
        if (ids.length > 1) {
            dggui.dialog.errors('只能选择一条数据！');
            return;
        }
        orderId = getIds(ids);
    }
    if (!orderId) {
        dggui.dialog.errors('请选择一条数据！');
        return;
    }
    dggui.dialog.loading();
    $.ajax({
        url: sysInfo.basePath + "/all_order/find_call_info.do",
        data: {id: orderId},
        type: "POST",
        dataType: "json",
        success: function (result) {
            dggui.dialog.loading('close');
            if (result.code == 0) {
                var customer = result.data;
                if (customer) {
                    callPhone(customer.id, customer.name, customer.phone, customer.phoneStr, "");
                } else {
                    dggui.dialog.errors("客户联系人未启用或号码不可拨打!");
                }
            } else {
                dggui.dialog.errors(result.msg);
            }
        }
    });
}

function getIds(data) {
    var ids = new Array();
    data.forEach(function (e) {
        ids.push(e.id.toString());
    });
    return ids.toString();
}

//恢复办理
function hintLayer(obj, type, scProductId) {
    var ids = getChecked(obj);
    var id = null;
    if (!isEmpty(obj)) {
        if (ids.length < 1) {
            dggui.dialog.errors('请至少选择一条数据！');
            return;
        }
        id = getIds(ids);
    } else {
        id = scProductId;
    }
    if (isEmpty(id)) {
        dggui.dialog.errors('生产订单ID为空！');
        return;
    }
    /*var target = $(".active").attr("data-target");*/
    var targetStatus = "RZSCORDER_STATUS09";//退单驳回
    //以后修改成弹框确认在修改
    if (type == 5) {
        targetStatus = "RZSCORDER_STATUS10";//废单驳回
    }
    //以后修改成弹框确认在修改
    if (type == 6) {
        targetStatus = "RZSCORDER_STATUS06";//已退单
    }
    //这里看以后是不是需要优化（如果这里提示需要具体的话 就不能做成匹配恢复）
    dggui.dialog.confire('<span style="color: #ff0000">注：确认恢复后，对应生产订单将进入生产办理中环节</span>', '恢复办理', function () {
        dggui.dialog.loading();
        $.ajax({
            url: sysInfo.basePath + '/all_order/restore_order.do',
            type: 'POST',
            dataType: 'JSON',
            data: {'id': id, 'status': targetStatus},
            success: function (data) {
                dggui.dialog.loading('close');
                if (data.code == 0) {
                    dggui.dialog.succeed('操作成功！');
                    //刷新列表
                    if (isEmpty(obj)) {
                        //详情页面过来的 刷新详情页面
                        window.location.reload();
                    } else {
                        reloadTable(obj, "reloadFalse");
                    }
                    /*search($('#rejectedOrder'));*/
                } else {
                    dggui.dialog.errors(data.msg);
                }
            },
            error: function () {
                dggui.dialog.loading('close');
                dggui.dialog.errors('发生异常，请稍后再试！');
            }
        });
    });

}

/**
 * 客户Id打电话
 * @param id  业务ID,不能为空
 * @param customerName  客户名字,不能为空
 * @param phone 解密后的电话号码,不能为空
 * @param callBackUrl  回调地址,可以为空
 */
function callPhone(id, customerName, phone, phoneStr, callBackUrl) {
    if (!checkEmpty(id)) {
        dggui.dialog.errors("业务ID不能为空!");
        return false;
    }
    if (!checkEmpty(customerName)) {
        dggui.dialog.errors("客户姓名不能为空!");
        return false;
    }
    if (!checkEmpty(phone)) {
        dggui.dialog.errors("电话号码不能为空!");
        return false;
    }
    //([{id:'7707874797615218681',name:'测试一号',phoneList:[{no: "18628979860", name: "测试一号"}]}], callBackUrl, 0)
    //组装参数
    var customers = [];
    var phoneList = [];
    var phoneInfo = {deNo: phone, name: customerName, no: phoneStr};
    phoneList.push(phoneInfo);
    var customer = {id: id, name: customerName, phoneList: phoneList};
    customers.push(customer);
    //调用IBOSS打电话  最后一个参数 0 表示单个拨打 目前该方法只支持单个拨打
    window.parent.dialing(customers, callBackUrl, 0);
}

/**
 * 列表操作
 *
 * @param obj 需要刷新的table
 * @param operation 操作   reloadFalse getCheck reload
 */
// function search(obj) {
//     dggui.dialog.loading();
//     dggui.use('table', function(){
//         // var table = dggui.table;
//
//         obj.ajax.reload();
//
//        /* table.render({
//             "elem":obj,
//             "type":"reload"
//         });*/
//     });
//     dggui.dialog.loading('close');
// }

// 清空搜索
function cleanSearch() {
    var $s = $('.screen-search');
    $('#signOrg').val('');
    $('#signOrg').next().val('');
    $('#signOrg').attr("data-id", null);
    $('#signOrg').data("param", "");
    $s.find('input').val('');
    $s.find('select').val('').trigger("change");
    var productCode = $("#productCode");
    var channelCode = $("#channelCode");
    var flowUserDep = $("flowUserDep");
    if (!isEmpty(productCode)) {
        $("#productCode").find("option").remove();
        $("#productCode").append("<option value=''>请选择</option>");
    }
    if (!isEmpty(channelCode)) {
        $("#channelCode").find("option").remove();
        $("#channelCode").append("<option value=''>请选择</option>");
    }
    if (!isEmpty(flowUserDep)) {
        $('#flowUserDep').val('');
        $('#flowUserDep').next().val('');
        $('#flowUserDep').attr("data-id", null);
        $('#flowUserDep').data("param", "");
    }

}


// 获取选中行数据
function getChecked(obj) {
    var checkedData = new Object();
    dggui.use('table', function () {
        var table = dggui.table;
        checkedData = table.render({"elem": obj, "type": "getCheck"});
    });
    return checkedData;
}
/**
 * 完结审核  obj  table对象
 */
function auditOrderDialogOne(id,obj) {
    var ids = new Array();
    ids.push(id.toString());
    auditOrderWj(ids,obj,1);
}

/**
 * 完结审核-批量  obj  table对象
 */
function auditOrderDialog(obj) {
    var data = getChecked(obj);
    if ('' == data || data.length == 0) {
        dggui.dialog.errors("请至少勾选一条数据审核！", 3000);
        return;
    }
    if (data.length > 10) {
        dggui.dialog.errors("最多同时选择10条数据！", 3000);
        return;
    }
    var ids = new Array();
    data.forEach(function (e) {
        if (null != e.id && '' != e.id) {
            ids.push(e.id.toString());
        }
    });
    auditOrderWj(ids,obj,data.length);
}

function auditOrderWj(ids, obj, num) {
    dggui.dialog.loading();
    var area = '500px';
    if(num > 1){
        area = '700px';
    }
    var idsJson = JSON.stringify(ids);
    $.ajax({
        url: sysInfo.basePath + "/rzsc/audit_order/audit_order_dialog.html",
        data: {ids: idsJson},
        success: function (html) {
            if (html.msg != null) {
                dggui.dialog.loading('close');
                dggui.dialog.errors(html.msg);
                return
            }
            index = dggui.dialog.open({
                content: html,
                area: area,
                title: '待审核',
                yes: function (index, layero) {
                    dggui.dialog.loading('close');
                    var auditParams = new Object();
                    var ids =[];
                    $("input[name='scOrderId']").each(function(){
                        ids.push($(this).val());
                    })
                    auditParams.ids = ids;
                    auditParams.auditResult = $("input[name='auditResult']:checked").val();
                    auditParams.remark = $("#remark").val();
                    if (isEmpty(auditParams.auditResult, '请选择审核结果')) {
                        return;
                    }
                    if(auditParams.auditResult == 1){
                        if(isEmpty(auditParams.remark)){
                            dggui.dialog.errors("驳回必须填写备注！");
                            return;
                        }
                    }
                    var params = JSON.stringify(auditParams);
                    dggui.dialog.confire('确认执行此操作？', '操作提示', function () {
                        dggui.dialog.loading();
                        $.ajax({
                            url: sysInfo.basePath + "/rzsc/audit_order/audit_order.do",
                            data: {params: params},
                            success: function (res) {
                                dggui.dialog.loading('close');
                                if (res.code == 0) {
                                    dggui.dialog.succeed(res.msg);
                                    layer.close(index);
                                    dggui.dialog.loading('close');
                                    if (isEmpty(obj)) {
                                        window.location.reload();
                                    } else {
                                        reloadTable(obj, "reload");
                                    }
                                } else {
                                    dggui.dialog.errors(res.msg);
                                }
                            }
                        });
                    });
                }
            })
        }
    });
}

/**
 * 退单审核  obj  table对象
 */
function abandonAudit(obj, scProductId) {
    if (!isEmpty(obj)) {
        var data = getChecked(obj);
        if ('' == data || data.length == 0) {
            dggui.dialog.errors("请选择要审核的数据！", 3000);
            return;
        }
        if (data.length == 1) {
            var id = data[0].id.toString();
            single(id);
        } else {
            var ids = new Array();
            data.forEach(function (e) {
                if (null != e.id && '' != e.id) {
                    ids.push(e.id.toString());
                }
            });
            mulity(ids);
            console.log("多个");
        }

    } else {
        if (isEmpty(scProductId)) {
            dggui.dialog.errors("生产单ID不能为空！", 3000);
            return;
        }
        single(scProductId);
    }

    function single(id) {
        dggui.dialog.loading();
        $.ajax({
            url: sysInfo.basePath + "/rzsc/audit_order/abandon_audit_dialog.html",
            data: {id: id},
            success: function (html) {
                if (html.msg != null) {
                    dggui.dialog.loading('close');
                    dggui.dialog.errors(html.msg);
                    return;
                }
                index = dggui.dialog.open({
                    content: html,
                    area: '500px',
                    title: '退单审核',
                    yes: function (index, layero) {
                        dggui.dialog.loading('close');
                        var auditParams = new Object();
                        auditParams.auditResult = $("#auditResult").val();
                        auditParams.remark = $("#remark").val();
                        auditParams.id = id;
                        var is = new Object();
                        var examineGrade = $("#examineGrade").attr("data-examineGrade");
                        // var abandonReasonNum = $("#abandonReasonNum").attr("data-abandonReasonNum");
                        var isLast = auditParams.auditResult == "0" && examineGrade;

                        if (isLast == "true") {
                            auditParams.nextAuditorId = $("#nextAuditor").val();
                            is = verifyEmpty($("#auditResult"), '请选择审核结果') &&
                                verifyEmpty($("#nextAuditor"), '请选择下一审核人') &&
                                verifyRemark($("#remark"), 1, 500, "请填写1-500字的备注信息");
                        } else {
                            is = (verifyEmpty($("#auditResult"), '请选择审核结果') &&
                                verifyRemark($("#remark"), 1, 500, "请填写1-500字的备注信息"));
                        }
                        if (is) {
                            var params = JSON.stringify(auditParams);
                            dggui.dialog.confire('确认执行此操作？', '操作提示', function () {
                                dggui.dialog.loading();
                                $.ajax({
                                    url: sysInfo.basePath + "/rzsc/audit_order/abandon_audit.do",
                                    data: {params: params},
                                    success: function (res) {

                                        dggui.dialog.loading('close');
                                        if (res.code == 0) {
                                            dggui.dialog.succeed(res.msg);
                                            layer.close(index);
                                            dggui.dialog.loading('close');
                                            if (isEmpty(obj)) {
                                                window.location.reload();
                                            } else {
                                                reloadTable(obj, "reload");
                                            }
                                        } else {
                                            dggui.dialog.errors(res.msg);
                                        }
                                    }
                                });
                            });

                        }
                    }
                })
            }
        });
    }

    function mulity(ids) {
        dggui.dialog.loading();
        var idsJson = JSON.stringify(ids);
        $.ajax({
            url: sysInfo.basePath + "/rzsc/audit_order/mulity_dialog.html",
            data: {ids: idsJson},
            success: function (html) {
                if (html.msg != null) {
                    dggui.dialog.loading('close');
                    dggui.dialog.errors(html.msg);
                    return
                }
                index = dggui.dialog.open({
                    content: html,
                    area: '500px',
                    title: '批量审核',
                    yes: function (index, layero) {
                        dggui.dialog.loading('close');
                        var auditParams = new Object();
                        auditParams.auditResult = $("#auditResult").val();
                        auditParams.ids = ids;
                        if (!verifyEmpty($("#auditResult"), '请选择审核结果')) {
                            return;
                        }

                        var params = JSON.stringify(auditParams);
                        dggui.dialog.confire('确认执行此操作？', '操作提示', function () {
                            dggui.dialog.loading();
                            $.ajax({
                                url: sysInfo.basePath + "/rzsc/audit_order/abandon_audit_mulity.do",
                                data: {params: params},
                                success: function (res) {

                                    dggui.dialog.loading('close');
                                    if (res.code == 0) {
                                        dggui.dialog.succeed(res.msg);
                                        layer.close(index);
                                        dggui.dialog.loading('close');
                                        if (isEmpty(obj)) {
                                            window.location.reload();
                                        } else {
                                            reloadTable(obj, "reload");
                                        }
                                    } else {
                                        dggui.dialog.errors(res.msg);
                                    }
                                }
                            });
                        });


                    }
                })
            }
        });


    }


}

/**
 * 废单审核  obj  table对象
 */
function nullifyAudit(obj, scProductId) {
    if (!isEmpty(obj)) {
        var data = getChecked(obj);
        if ('' == data || data.length == 0) {
            dggui.dialog.errors("请选择要审核的数据！", 3000);
            return;
        }
        if (data.length == 1) {
            var id = data[0].id.toString();
            single(id);
        } else {
            var ids = new Array();
            data.forEach(function (e) {
                if (null != e.id && '' != e.id) {
                    ids.push(e.id.toString());
                }
            });
            mulity(ids);
            console.log("多个");
        }

    } else {
        if (isEmpty(scProductId)) {
            dggui.dialog.errors("生产单ID不能为空！", 3000);
            return;
        }
        single(scProductId);
    }


    function single(id) {
        dggui.dialog.loading();
        $.ajax({
            url: sysInfo.basePath + "/rzsc/audit_order/nullify_audit_dialog.html",
            data: {id: id},
            success: function (html) {
                if (html.msg != null) {
                    dggui.dialog.loading('close');
                    dggui.dialog.errors(html.msg);
                    return;
                }
                index = dggui.dialog.open({
                    content: html,
                    area: '500px',
                    title: '废单审核',
                    yes: function (index, layero) {
                        dggui.dialog.loading('close');
                        var auditParams = new Object();
                        auditParams.auditResult = $("#auditResult").val();
                        auditParams.remark = $("#remark").val();
                        auditParams.id = id;
                        var is = new Object();
                        var examineGrade = $("#examineGrade").attr("data-examineGrade");
                        // var abandonReasonNum = $("#abandonReasonNum").attr("data-abandonReasonNum");
                        var isLast = auditParams.auditResult == "0" && examineGrade;

                        if (isLast == "true") {
                            auditParams.nextAuditorId = $("#nextAuditor").val();
                            is = verifyEmpty($("#auditResult"), '请选择审核结果') &&
                                verifyEmpty($("#nextAuditor"), '请选择下一审核人') &&
                                verifyRemark($("#remark"), 1, 500, "请填写1-500字的备注信息");
                        } else {
                            is = (verifyEmpty($("#auditResult"), '请选择审核结果') &&
                                verifyRemark($("#remark"), 1, 500, "请填写1-500字的备注信息"));
                        }
                        if (is) {
                            var params = JSON.stringify(auditParams);
                            dggui.dialog.confire('确认执行此操作？', '操作提示', function () {
                                dggui.dialog.loading();
                                $.ajax({
                                    url: sysInfo.basePath + "/rzsc/audit_order/nullify_audit.do",
                                    data: {params: params},
                                    success: function (res) {
                                        dggui.dialog.loading('close');
                                        if (res.code == 0) {
                                            dggui.dialog.loading('close');
                                            dggui.dialog.succeed(res.msg);
                                            layer.close(index);
                                            if (isEmpty(obj)) {
                                                window.location.reload();
                                            } else {
                                                reloadTable(obj, "reload");
                                            }
                                        } else {
                                            dggui.dialog.errors(res.msg);
                                        }
                                    }
                                });
                            });

                        }
                    }
                })
            }
        })
    };

    function mulity(ids) {
        dggui.dialog.loading();
        var idsJson = JSON.stringify(ids);
        $.ajax({
            url: sysInfo.basePath + "/rzsc/audit_order/mulity_dialog.html",
            data: {ids: idsJson},
            success: function (html) {
                if (html.msg != null) {
                    dggui.dialog.loading('close');
                    dggui.dialog.errors(html.msg);
                    return
                }
                index = dggui.dialog.open({
                    content: html,
                    area: '500px',
                    title: '批量审核',
                    yes: function (index, layero) {
                        dggui.dialog.loading('close');
                        var auditParams = new Object();
                        auditParams.auditResult = $("#auditResult").val();
                        auditParams.ids = ids;
                        if (!verifyEmpty($("#auditResult"), '请选择审核结果')) {
                            return;
                        }

                        var params = JSON.stringify(auditParams);
                        dggui.dialog.confire('确认执行此操作？', '操作提示', function () {
                            dggui.dialog.loading();
                            $.ajax({
                                url: sysInfo.basePath + "/rzsc/audit_order/nullify_audit_mulity.do",
                                data: {params: params},
                                success: function (res) {

                                    dggui.dialog.loading('close');
                                    if (res.code == 0) {
                                        dggui.dialog.succeed(res.msg);
                                        layer.close(index);
                                        dggui.dialog.loading('close');
                                        if (isEmpty(obj)) {
                                            window.location.reload();
                                        } else {
                                            reloadTable(obj, "reload");
                                        }
                                    } else {
                                        dggui.dialog.errors(res.msg);
                                    }
                                }
                            });
                        });


                    }
                })
            }
        });
    };


}


//判断js内容是否为空
function isEmpty(obj) {
    if (typeof obj == "undefined" || obj == null || obj == "") {
        return true;
    } else {
        return false;
    }
}

/**
 * 订单转单
 * @param ids 生产订单id,如果是批量，则用英文逗号分隔
 */
function transferOrder(ids, obj) {
    if (isEmpty(ids)) {
        dggui.dialog.errors("生产订单id不能为空");
        return false;
    }
    dggui.dialog.loading();
    $.post(sysInfo.basePath + "/rzsc/processing_order/transfer_order_page.do", {}, function (html) {
        dggui.dialog.loading('close');
        dggui.dialog.open({
            content: html,
            title: "订单转单",
            area: ['700px', '320px'],
            yes: function (index, layero) {
                if (!verifyEmpty($("#transferUserId"), "请选择")) {
                    return false;
                }
                if (!verifyRemark($("#transfer_order_remark"), 1, 500, "请填写1-500字的备注信息")) {
                    return false;
                }
                var param = {
                    orderIds: ids,
                    transferUserId: $("#transferUserId").val(),
                    transferOrderRemark: $("#transfer_order_remark").val()
                };//获取退回参数
                dggui.dialog.loading();
                $.post(sysInfo.basePath + "/rzsc/processing_order/transfer_order.do", param, function (result) {
                    dggui.dialog.loading('close');
                    if (result.code == 0) {
                        dggui.dialog.succeed('转单成功');
                        layer.close(index);
                        reloadTable(obj, "reload");
                    } else {
                        dggui.dialog.errors(result.msg);
                    }
                }, 'json');
            }
        })
    }, 'html');
}

/**
 * 跨事业部移交
 * @param orderIds 销售订单id
 */
function trunOverFromOrg(orderId, obj) {
    if (isEmpty(orderId)) {
        dggui.dialog.errors("销售订单id不能为空");
        return false;
    }
    dggui.dialog.loading();
    $.post(sysInfo.basePath + "/org_order/transfer_org_order_page.do", {orderId: orderId}, function (html) {
        dggui.dialog.loading('close');
        dggui.dialog.open({
            content: html,
            title: "跨事业部移交",
            area: ['830px', '500px'],
            yes: function (index, layero) {
                saveOrgTransfer(orderId, index, obj);
                /*var transferUserId = $("#transferUserId").val();
                if(!verifyEmpty($("#transferUserId"),"请选择"))
                    return false;
                var return_remark = $("#transfer_order_remark").val();
                if(return_remark.length>200){
                    dggui.dialog.warning("备注内容不能超过200字");
                    return false;
                }
                var param ={orderIds : ids,transferUserId:$("#transferUserId").val(),transferOrderRemark:$("#transfer_order_remark").val()};//获取退回参数
                console.log(param);
                dggui.dialog.loading();
                $.post(sysInfo.basePath+"/rzsc/processing_order/transfer_order.do",param,function(result){
                    dggui.dialog.loading('close');
                    if(result.code==0){
                        dggui.dialog.succeed('转单成功');
                        layer.close(index);
                        reloadTable(obj,"reload");
                    }else{
                        dggui.dialog.errors(result.msg);
                    }
                },'json');*/
            }
        })
    }, 'html');
}

/**
 * 退单、废单审核撤回
 */

function withdrawn(obj, scProductId) {
    var preWithdrawnParams = new Object();
    if (!isEmpty(obj)) {
        var data = getChecked(obj);
        if ("" == data || data.length == 0) {
            dggui.dialog.errors("请至少选择一条要撤回的数据！", 3000);
            return;
        }
        var ids = new Array();
        data.forEach(function (e) {
            ids.push(e.id.toString());
        });
        preWithdrawnParams.ids = ids;
    } else {
        if (isEmpty(scProductId)) {
            dggui.dialog.errors("生产单ID不能为空！", 3000);
            return;
        }
        var ids = new Array();
        ids.push(scProductId);
        preWithdrawnParams.ids = ids;
    }
    dggui.dialog.confire('确认执行此操作？', '操作提示', function () {
        dggui.dialog.loading();
        $.ajax({
            url: sysInfo.basePath + "/rzsc/audit_order/withdrawn.do",
            data: {params: JSON.stringify(preWithdrawnParams)},
            success: function (res) {
                if (res.code != 0) {
                    dggui.dialog.loading('close');
                    dggui.dialog.errors(res.msg);
                } else {
                    dggui.dialog.loading('close');
                    dggui.dialog.succeed(res.msg);
                    if (isEmpty(obj)) {
                        window.location.reload();
                    } else {
                        reloadTable(obj, "reload");
                    }
                }
            }
        })
    });

}


/**
 * 变更审核人
 */

function changeAudtor(obj, scProductid) {
    var id = null;
    var productOrgId = null;
    if (!isEmpty(obj)) {
        var objStr = obj.selector;
        var data = getChecked(obj);
        if ("" == data) {
            dggui.dialog.errors("请选择一条要审核的数据！", 3000);
            return;
        }else if(data.length==1){
            id = data[0].id.toString();
        }else {
            productOrgId = data[0].productOrgId.toString();
           for(var i=1;i<data.length;i++){
               var productOId = data[i].productOrgId.toString();
               if(productOId != productOrgId){
                   dggui.dialog.errors("不能选择不同生产所属事业部的生产单！", 3000);
                   return;
               }
           }
        }
    } else {
        if (isEmpty(scProductid)) {
            dggui.dialog.errors("生产单ID不能为空！", 3000);
            return;
        }
        id = scProductid;
    }
    dggui.dialog.loading();
    $.ajax({
        url: sysInfo.basePath + "/rzsc/audit_order/change_auditor_dialog.html",
        data: {id: id,objId:objStr},
        success: function (html) {
            if (html.msg != null) {
                dggui.dialog.loading('close');
                dggui.dialog.errors(html.msg);
            }
            index = dggui.dialog.open({
                content: html,
                area: '500px',
                title: '变更审核人',
                yes: function (index, layero) {
                    dggui.dialog.loading('close');
                    var auditParams = new Object();
                    auditParams.remark = $("#remark").val();
                    auditParams.otherAuditorId = $("#otherAuditor").val();
                    if(id==null){
                        var ids = [];
                        var dataIds = getChecked(obj);
                        for(var i=0;i<dataIds.length;i++){
                            ids.push(dataIds[i].id.toString());
                        }
                        auditParams.ids = JSON.stringify(ids);
                    }
                    auditParams.id = id;
                    var is = new Object();

                    is = (verifyEmpty($("#otherAuditor"), '请选择下一审核人') &&
                        verifyRemark($("#remark"), 1, 500, "请填写1-500字的备注信息"));

                    if (is) {
                        var params = JSON.stringify(auditParams);
                        dggui.dialog.confire('确认执行此操作？', '操作提示', function () {
                            dggui.dialog.loading();
                            $.ajax({
                                url: sysInfo.basePath + "/rzsc/audit_order/chang_auditor.do",
                                data: {params: params},
                                success: function (res) {

                                    dggui.dialog.loading('close');
                                    if (res.code == 0) {
                                        dggui.dialog.loading('close');
                                        layer.close(index);
                                        dggui.dialog.succeed(res.msg);
                                        if (isEmpty(obj)) {
                                            window.location.reload();
                                        } else {
                                            reloadTable(obj, "reload");
                                        }
                                    } else {
                                        dggui.dialog.loading('close');
                                        dggui.dialog.errors(res.msg);
                                    }
                                }
                            });
                            // reloadTable(obj)
                        });

                    }
                }
            })
        }
    })

}


/*----------------更新节点------------------------------*/
/**
 *
 * @param tableName  表格table名称
 * @param id  生产订单id
 */
var subjectIndex;

function openUpdateNode(tableName, selectId, scProductNo, nodeId) {
    if (!isEmpty(tableName) || !isEmpty(selectId)) {
        var id;

        if (!isEmpty(tableName)) {
            //获取选中行对象
            var trs = getChecked("#" + tableName);
            if (trs.length > 1) {
                dggui.dialog.errors('只能选择一条数据')
                return;
            }
            if (trs.length == 0) {
                dggui.dialog.errors('请选择一条数据');
                return;
            }
            id = trs[0].id;
        }
        if (!isEmpty(selectId)) {
            id = selectId;
        }

        dggui.dialog.loading();
        $.ajax({
            type: 'POST',
            url: sysInfo.basePath + "/rzsc/flow/openUpdateNode.html",
            data: {
                id: id,
                nodeId: nodeId
            },
            success: function (resHtml) {
                if (resHtml.msg == null) {//后台没有异常

                    subjectIndex = dggui.dialog.open({
                        title: '更新节点',
                        content: resHtml,
                        area: '500px',

                        //弹框之后回调函数
                        success: function (layero, index) {
                            dgg.dialog.relocation(subjectIndex);//弹框重新布局
                            dggui.dialog.loading('close');
                            $('.nodeLayerIndex').val(index);
                        },

                        //点击确定触发
                        yes: function (index, layero) {
                            var ids = $("#completenode").find("option:selected").attr("data-ids");
                            var newids = ids.split(",");
                            var completenodename = $("#completenode").find("option:selected").text();//节点名称
                            if (!verification(newids, completenodename)) {
                                //验证
                                return;
                            }//如果其中一条没有验证通过，结束
                            var params = $("#nodeUpdateform").serializeArray();//保存自定义字段
                            var completenodeid = $("#completenode").find("option:selected").val();//select选中的节点id
                            var completenodename = $("#completenode").find("option:selected").text();//节点名称
                            var productId = $('#id').val();//主订单id
                            //判断备注信息是否为空
                            params.push({name: 'completenodeid', value: completenodeid});//select选中的节点id
                            params.push({name: 'completenodename', value: completenodename});//节点名称
                            params.push({name: 'id', value: productId});//主订单id
                            params.push({name: 'remark', value: remark});//备注
                            console.log(params);
                            dggui.dialog.confire((completenodename == '完结' || completenodename == '强制完结') ? "请确认已经放款" : '确定更新节点吗？', '操作提示', function () {
                                dggui.dialog.loading();
                                $.ajax({
                                    type: 'POST',
                                    data: params,
                                    url: sysInfo.basePath + "/rzsc/flow/saveNodeUpdate.do",
                                    dataType: 'JSON',
                                    success: function (data) {
                                        dggui.dialog.loading('close')
                                        if (data.code == 0) {//保存成功
                                            dggui.dialog.succeed(data.msg, 2000);
                                            layer.close(index);//关闭弹框
                                            //刷新列表
                                            if (!isEmpty(tableName)) {
                                                reloadTable("#" + tableName, "reloadFalse");
                                            } else {//说明是订单详情过来的 刷新详情页面
                                                window.location.reload();
                                            }
                                        } else {
                                            dggui.dialog.errors(data.msg);
                                        }
                                    },
                                    error: function () {
                                        dggui.dialog.loading('close')
                                        dggui.dialog.errors("发生异常，请稍后再试！");
                                    }
                                });
                            })

                        }//yes end
                    })//open end
                } else {
                    dggui.dialog.errors(resHtml.msg);
                    dggui.dialog.loading('close')
                }
            }//success end
        })//ajax end
    }
}//openUpdateNode end

/*-------------验证金额----------------*/
function regixNumber(obj) {
    isFloat = /^[1-9]\d{0,7}(\.\d{2})?$/;
    var result = isFloat.test(obj.val())
    if (!result) {
        dggui.dialog.tip('金额最大8位数，精度是小数点后两位', obj, {tipsMore: true})
        return false;
    }
    return true;
}

/*-------------验证长度----------------*/
/**
 *
 * @param obj  dom对象
 * @param len 长度
 * @param msg 提示信息
 * @returns {boolean}
 */
function strLength(obj, len, msg) {
    var val = obj.val().trim();
    if (val.length > len) {
        dggui.dialog.tip(msg, obj, {tipsMore: true})
        return false;
    }
    return true;
}

/*-------------验证输入内容----------------*/
/**
 *
 * @param ids  需要验证的节点
 * @returns {boolean}
 */
function verification(ids, completenodename) {
    //签申请时间  非必填
    //报审时间  非必填
    //通过时间  非必填
    //还款到期日 非必填
    //评估公司
    if (!isEmpty($("#escrowCompanys").val().trim())) {
        if (!strLength($("#escrowCompanys"), 200, '长度不能超过200')) {
            /*flag=false;//验证错误*/
            return false;
        }
    }

    //评估费用

    if (!isEmpty($("#appraisalCosts").val())) {
        if (!isNumberTip($("#appraisalCosts"), "请输入正确的数字", "价格不能超过99999999999")) {
            /* flag=false;//验证错误*/
            return false;
        }
    }

    //征信（好/差） 必填
    var aa = $("#credits").parents(".poerate-box");
    if (ids.indexOf($("#credits").parents(".poerate-box").attr("data-id")) != -1) {//获取输入框 父级class是poerat-box的对象，获取data-id属性。如果节点对应自定义字段 需要验证的自定义字段进行验证
        if (!isEmpty($("#credits").val().trim())) {
            if ($("#credits").val().trim() != '好' && $("#credits").val().trim() != '差') {
                dggui.dialog.tip('征信只能输入好或差', $("#credits"), {tipsMore: true})
                /*flag = false;*/
                return false;
            }
        } else {
            dggui.dialog.tip('征信不能为空', $("#credits"), {tipsMore: true})
            /* flag = false;*/
            return false;
        }
    }

    //申请金额


    if (!isEmpty($("#loanAmounts").val())) {
        if (!isNumberTip($("#loanAmounts"), "请输入正确的数字", "价格不能超过99999999999")) {
            /* flag=false;//验证错误*/
            return false;
        }
    }

    //通过金额  必填
    if (ids.indexOf($("#approveMoneys").parents(".poerate-box").attr("data-id")) != -1) {//需要验证的自定义字段 是当前输入框的data-id
        if (!isEmpty($("#approveMoneys").val())) {
            if (!isNumberTip($("#approveMoneys"), "请输入正确的数字", "价格不能超过99999999999")) {
                /* flag = false;//验证错误*/
                return false;
            }
        } else {
            dggui.dialog.tip('通过金额不能为空', $("#approveMoneys"), {tipsMore: true})
            /*flag = false;*/
            return false;
        }
    }


    //结案银行  必填
    if (ids.indexOf($("#settlementBanks").parents(".poerate-box").attr("data-id")) != -1) {//需要验证的自定义字段 是当前输入框的data-id
        if (!isEmpty($("#settlementBanks").val().trim())) {
            if (!strLength($("#settlementBanks"), 50, '长度不能超过50')) {
                /*flag = false;//验证错误*/
                return false;
            }
        } else {
            dggui.dialog.tip('结案银行不能为空', $("#settlementBanks"), {tipsMore: true})
            /*flag = false;*/
            return false;
        }
    }

    //注销时间  必填
    if (ids.indexOf($("#advanceFundCancels").parents(".poerate-box").attr("data-id")) != -1) {//需要验证的自定义字段 是当前输入框的data-id
        if (isEmpty($("#advanceFundCancels").val())) {
            dggui.dialog.tip('注销时间不能为空', $("#advanceFundCancels"), {tipsMore: true})
            /*flag = false;*/
            return false;
        }
    }

    //办抵押时间  必填
    if (ids.indexOf($("#mortgageTimes").parents(".poerate-box").attr("data-id")) != -1) {//需要验证的自定义字段 是当前输入框的data-id
        if (isEmpty($("#mortgageTimes").val())) {
            dggui.dialog.tip('办抵押时间不能为空', $("#mortgageTimes"), {tipsMore: true})
            // flag = false;
            return false;
        }
    }

    //取他权时间  必填
    if (ids.indexOf($("#takeHisTimes").parents(".poerate-box").attr("data-id")) != -1) {//需要验证的自定义字段 是当前输入框的data-id
        if (isEmpty($("#takeHisTimes").val())) {
            dggui.dialog.tip('取他权时间不能为空', $("#takeHisTimes"), {tipsMore: true})
            /* flag = false;*/
            return false;
        }
    }

    //放款时间  必填
    if (ids.indexOf($("#loanTimes").parents(".poerate-box").attr("data-id")) != -1) {//需要验证的自定义字段 是当前输入框的data-id
        if (isEmpty($("#loanTimes").val())) {
            dggui.dialog.tip('放款时间不能为空', $("#loanTimes"), {tipsMore: true})
            /*flag = false;*/
            return false;
        }
    }

    //放款时长(天)  必填
    if (ids.indexOf($("#loanTimeDays").parents(".poerate-box").attr("data-id")) != -1) {//需要验证的自定义字段 是当前输入框的data-id
        if (!isEmpty($("#loanTimeDays").val())) {
            isFloat = /^[1-9]\d{0,2}$/;
            var result = isFloat.test($("#loanTimeDays").val())
            if (!result) {
                dggui.dialog.tip('只能3位以下正整数', $("#loanTimeDays"), {tipsMore: true})
                /* flag = false;*/
                return false;
            }
        } else {
            dggui.dialog.tip('放款时长不能为空', $("#loanTimeDays"), {tipsMore: true});
            /* flag = false;*/
            return false;
        }
    }


    //还款时间  必填
    if (ids.indexOf($("input[name='dateOfLoan']:not(:hidden)").parents(".poerate-box").attr("data-id")) != -1) {//需要验证的自定义字段 是当前输入框的data-id
        if (isEmpty($("input[name='dateOfLoan']:not(:hidden)").val().trim())) {
            dggui.dialog.tip('还款时间不能为空', $("input[name='dateOfLoan']:not(:hidden)"), {tipsMore: true});
            /*flag = false;*/
            return false;
        }
    }

    //后台结算金额  非必填
    if (!isEmpty($("#settlementAmounts").val())) {
        if (!isNumberTip($("#settlementAmounts"), "请输入正确的数字", "价格不能超过99999999999")) {
            /*flag=false;//验证错误*/
            return false;
        }
    }

    //渠道返点  必填
    /* if(!isEmpty($("#channelRebatess").val())){
         if(!isNumberTip($("#channelRebatess"), "请输入正确的数字", "价格不能超过99999999999")){
             /!*flag=false;//验证错误*!/
             return false;
         }
     }*/
    if (ids.indexOf($("#channelRebatess").parents(".poerate-box").attr("data-id")) != -1) {//需要验证的自定义字段 是当前输入框的data-id
        if (!isEmpty($("#channelRebatess").val())) {
            if (!isNumberTip($("#channelRebatess"), "请输入正确的数字", "价格不能超过99999999999")) {
                return false;
            }
        } else {
            dggui.dialog.tip('渠道返点不能为空', $("#channelRebatess"), {tipsMore: true});
            return false;
        }
    }

    //对外返点   非必填
    if (!isEmpty($("#foreignRebatess").val())) {
        if (!isNumberTip($("#foreignRebatess"), "请输入正确的数字", "价格不能超过99999999999")) {
            /*flag=false;//验证错误*/
            return false;
        }
    }

    //每期还款金额/月
    if (!isEmpty($("#installmentRepayments").val())) {
        if (!isNumberTip($("#installmentRepayments"), "请输入正确的数字", "价格不能超过99999999999")) {
            /*flag=false;//验证错误*/
            return false;
        }
    }

    //放款金额  必填
    if (ids.indexOf($("#loanMoneys").parents(".poerate-box").attr("data-id")) != -1) {//需要验证的自定义字段 是当前输入框的data-id

        if (!isEmpty($("#loanMoneys").val())) {
            if (!isNumberTip($("#loanMoneys"), "请输入正确的数字", "价格不能超过99999999999")) {
                /*flag = false;//验证错误*/
                return false;
            }
        } else {
            dggui.dialog.tip('放款金额不能为空', $("#loanMoneys"), {tipsMore: true})
            /*flag = false;*/
            return false;
        }
    }
    //下次更新时间不必须填写了
    /*if (completenodename != "完结" && completenodename != "强制完结") {
        //下次跟进时间(如果是完结或者强制完结下次跟进时间没有)
        if (isEmpty($("#nextFollowTime").val())) {
            dggui.dialog.tip('下次跟进时间不能为空', $("#nextFollowTime"),{tipsMore: true})
           /!* flag = false;*!/
            return false;
        }
    }*/
    if (ids.indexOf($("#capitalUsess").parents(".poerate-box").attr("data-id")) != -1) {//获取输入框 父级class是poerat-box的对象，获取data-id属性。如果节点对应自定义字段 需要验证的自定义字段进行验证
        if (isEmpty($("#capitalUsess").val().trim())) {
            dggui.dialog.tip('资金用途不能为空', $("#capitalUsess"), {tipsMore: true})
            /* flag = false;*/
            return false;
        }
    }

    if (ids.indexOf("17") == -1) {
        if ($("#remark").val().trim() != '') {
            if (!verifyRemark($("#remark"), 0, 500, "请填写0-500字的备注信息")) {
                return false;
            }
        }
    }
    // var remark = $('#remark').val().trim();//将备注空格清除
    //产权性质   非必填
    if (ids.indexOf("26") != -1) {
        if (!isEmpty($("#interestType").val().trim())) {
            if ($("#interestType").val() != 1 && $("#interestType").val() != 2 && $("#interestType").val() != 3) {
                dggui.dialog.tip('产权性质参数错误', $("#interestType"), {tipsMore: true})
                return false;
            }
        }
    }

    if (ids.indexOf("27") != -1) {
        if (!isEmpty($("#address").val().trim())) {
            if (!verifyRemark($("#address"), 1, 50, "请填写1-50位地址")) {
                return false;
            }
        }
    }

    if (ids.indexOf("28") != -1) {
        if (!isEmpty($("#area").val().trim())) {
            if (!verifyRemark($("#area"), 1, 50, "请填写1-50位面积")) {
                return false;
            }
        }
    }

    //按揭/全款   非必填
    if (ids.indexOf("29") != -1) {
        if (!isEmpty($("#refundType").val().trim())) {
            if ($("#refundType").val() != 1 && $("#refundType").val() != 2 && $("#refundType").val() != 3) {
                dggui.dialog.tip('产权性质参数错误', $("#refundType"), {tipsMore: true})
                return false;
            }
        }
    }
    return true;

}


/**
 * 获取文件后缀名，返回大写的后缀
 * @param fileName
 */
function getFileExt(fileName) {
    if (isEmpty(fileName)) {
        dggui.dialog.errors("文件名错误！");
        return false;
    }
    var extStart = fileName.lastIndexOf(".");
    if (extStart < 0) {
        dggui.dialog.errors("文件名错误！");
        return false;
    }
    return fileName.substring(extStart, fileName.length).toUpperCase();
}

/**
 * 判断是否是图片
 * @param filepath
 * @returns {boolean}
 */
function isImgFile(filepath) {
    var ext = getFileExt(filepath);
    return (ext == ".BMP" || ext == ".PNG" || ext == ".GIF" || ext == ".JPG" || ext == ".JPEG");
}

/**
 * 根据文件的后缀名获取文件的样式
 */
function getFileClass(ext) {
    var className = "";
    switch (ext) {
        case ".XLSX" :
            className = "icon-excel";
            break;
        case ".XLS" :
            className = "icon-excel";
            break;
        case ".DOCX" :
            className = "icon-word";
            break;
        case ".DOC" :
            className = "icon-word";
            break;
        case ".PDF" :
            className = "icon-pdf";
            break;
        case ".ZIP" :
            className = "icon-zip";
            break;
        case ".PPT" :
            className = "icon-ppt";
            break;
        case ".TXT" :
            className = "icon-txt1";
            break;
        case ".PNG" :
            className = "icon-photo";
            break;
        case ".GIF" :
            className = "icon-photo";
            break;
        case ".JPG" :
            className = "icon-photo";
            break;
        case ".JPEG" :
            className = "icon-photo";
            break;
        default:
            className = "icon-unknown";
            break;
    }
    return className;
}


/**
 * 导出
 * */
function excelExport(obj) {
    $(obj).submit();
}

/**
 * 还款时间编辑弹窗
 */
function getLoanWayAndTime() {
    var html = new Array();
    html.push("<div class=\"distribPersonel dialog-warp-ajax\">");
    html.push("<form action=\"\" id=\"LoanWayAndTime\" >");
    html.push("<table class='dggui-table-info'>");
    html.push("<tbody>");
    html.push("<tr>");
    html.push("<th class='required'>还款方式：</th>");
    html.push("<td>");
    html.push("<select onchange='changeWay()' class=\"dggui-select\" id=\"wayOfLoan_dialog\">");
    html.push("<option value=\"3\">先息后本</option>");
    html.push("<option value=\"4\">等额等息</option>");
    html.push("<option value=\"5\">等额本金</option>");
    html.push("<option value=\"6\">等本等息</option>");
    html.push("<option value=\"7\">减本减息</option>");
    html.push("<option value=\"8\">计划归本</option>");
    html.push(" <option value=\"1\">分期还款</option>");
    html.push("<option value=\"2\">其他</option>");
    html.push("</select>");
    html.push("</td>");
    html.push("</tr>");
    html.push("<tr>");
    html.push("<th class='required'>还款时间：</th>");
    html.push("<td><input id=\"dateOfLoan_dialog1\" type=\"hidden\" class=\"dggui-input\"><input id=\"dateOfLoan_dialog\" type=\"text\" class=\"dggui-input dggui-input-time\"><i id=\'datacss\' class=\"iconfont icon-rili\"></i></td>");
    html.push("</tr>");
    html.push("</tbody>");
    html.push("</table>");
    html.push("</form>");
    html.push("</div>");
    html = html.join('');
    dggui.dialog.open({
        content: html,
        title: "还款时间编辑",
        area: '380px',
        success: function () {
            $("#wayOfLoan_dialog").val($("#wayOfLoan").attr("data-old"));
            $("#dateOfLoan_dialog").val($("#dateOfLoan").attr("data-old"));
            var type = $("#wayOfLoan_dialog").val();
            if (type == 1 || type == 2 || type == 8) {
                $("#dateOfLoan_dialog1").attr("type", "text");
                $("#dateOfLoan_dialog").attr("type", "hidden");
                $("#datacss").hide();
                $("#dateOfLoan_dialog1").val($("#dateOfLoan").attr("data-old"));
            } else {
                $("#datacss").show();
                $("#dateOfLoan_dialog1").attr("type", "hidden");
                $("#dateOfLoan_dialog").attr("type", "text");
                $("#dateOfLoan_dialog").val($("#dateOfLoan").attr("data-old"));
            }
            //初始化日期控件
            dggui.use('dggdate', function () {
                var dggdate = dggui.dggdate;
                dggdate.render({
                    elem: '#dateOfLoan_dialog',//绑定标签名
                    format: 'dd', //可任意组合
                    /*type: 'time',//日期格式类型 年月日*/
                    btns: ['clear', 'now', 'confirm'],//显示清除和现在按钮
                    done: function (value, date, endDate) {
                        $("#dateOfLoan_dialog").val(value);
                    }
                });
            });
        },
        yes: function (index, layero) {
            var way = $("#wayOfLoan_dialog").val();
            var date = "";
            if (way == 1 || way == 2 || way == 8) {
                date = $("#dateOfLoan_dialog1").val();
                if (!verifyEmpty($("#dateOfLoan_dialog1"), "不能为空")) {
                    return false;
                }
            } else {
                date = $("#dateOfLoan_dialog").val();
                if (!verifyEmpty($("#dateOfLoan_dialog"), "不能为空")) {
                    return false;
                }
            }
            if (!verifyEmpty($("#wayOfLoan_dialog"), "不能为空")) {
                return false;
            }
            if (way != '1' && way != '2' && way != '8') {
                if (!verifyDay($("#dateOfLoan_dialog"), "日期不正确")) {
                    return false;
                }
                date = parseInt(date);
            }
            date = encodeHtml(date);
            var txt = joinLoanWayAndTime(way, date);
            $("#loan_way_and_date_txt").html(txt);
            $("#wayOfLoan").val(way);
            $("#dateOfLoan").val(date);
            layer.close(index);

        }
    })
}

function changeWay() {
    //清空值
    $("#dateOfLoan_dialog1").val('');
    $("#dateOfLoan_dialog").val('');
    var id = $("#wayOfLoan_dialog").val();
    if (id != 1 && id != 2 && id != 8) {
        $("#datacss").show();
        $("#dateOfLoan_dialog1").attr("type", "hidden");
        $("#dateOfLoan_dialog").attr("type", "text");
        //需要初始化时间空间其余不需要
        /*-----------绑定layui日期样式----------------------------------------------------*/
        dggui.use('dggdate', function () {
            var dggdate = dggui.dggdate;
            dggdate.render({
                elem: '#dateOfLoan_dialog',//绑定标签名
                format: 'dd', //可任意组合
                /*type: 'time',//日期格式类型 年月日*/
                btns: ['clear', 'now', 'confirm'],//显示清除和现在按钮
                done: function (value, date, endDate) {
                    $("#dateOfLoan_dialog").val(value);
                }
            });
        });
    } else {
        $("#dateOfLoan_dialog1").attr("type", "text");
        $("#dateOfLoan_dialog").attr("type", "hidden");
        $("#datacss").hide();
    }

}

function joinLoanWayAndTime(way, time) {
    var txt = "";
    switch (way) {
        case "1" :
            txt = "分期还款";
            break;
        case "2" :
            txt = "其他";
            break;
        case "3" :
            txt = "先息后本";
            break;
        case "4" :
            txt = "等额等息";
            break;
        case "5" :
            txt = "等额本金";
            break;
        case "6" :
            txt = "等本等息";
            break;
        case "7" :
            txt = "减本减息";
            break;
        case "8" :
            txt = "计划归还";
            break;
    }
    if (isEmpty(way) || isEmpty(time)) {
        return "<a href=\"javascript:;\" class=\"dggui-link\" onclick=\"getLoanWayAndTime()\">请编辑还款时间</a>";
    }
    if (way == '1' || way == '2' || way == '8') {
        txt += " " + time;
    } else {
        txt += " 每月" + time + "号";
    }
    return "<a href=\"javascript:;\" class=\"dggui-link\" onclick=\"getLoanWayAndTime()\">" + txt + "</a>";
}

function joinLoanWayAndTimeTxt(way, time) {
    var txt = "";
    switch (way) {
        case "1" :
            txt = "分期还款";
            break;
        case "2" :
            txt = "其他";
            break;
        case "3" :
            txt = "先息后本";
            break;
        case "4" :
            txt = "等额等息";
            break;
        case "5" :
            txt = "等额本金";
            break;
        case "6" :
            txt = "等本等息";
            break;
        case "7" :
            txt = "减本减息";
            break;
        case "8" :
            txt = "计划归还";
            break;
    }
    if (way == '1' || way == '2' || way == '8') {
        txt += " " + time;
    } else {
        txt += " 每月" + time + "号";
    }
    if (!checkEmpty(way) || !checkEmpty(time)) {
        txt = "";
    }
    return txt;
}

function joinLoanWayAndTimeTxt(way, time) {
    var txt = "";
    switch (way) {
        case "1" :
            txt = "分期还款";
            break;
        case "2" :
            txt = "其他";
            break;
        case "3" :
            txt = "先息后本";
            break;
        case "4" :
            txt = "等额等息";
            break;
        case "5" :
            txt = "等额本金";
            break;
        case "6" :
            txt = "等本等息";
            break;
        case "7" :
            txt = "减本减息";
            break;
        case "8" :
            txt = "计划归还";
            break;
    }
    if (way == '1' || way == '2' || way == '8') {
        txt += " " + time;
    } else {
        txt += " 每月" + time + "号";
    }
    if (!checkEmpty(way) || !checkEmpty(time)) {
        txt = "";
    }
    return txt;
}

//刷新table，obj 为table对象，operation为操作（reload刷新分页数据,reloadfalse不改变分页）
function reloadTable(obj, operation) {
    if (!isEmpty(obj) && !isEmpty(operation)) {
        dggui.use('table', function () {
            var is = isEmpty(operation);
            var table = dggui.table;
            table.render({"elem": obj, "type": operation});
        });
    } else {
        window.location.reload();
    }
}

/**
 * 三方卡编辑弹窗
 */
function getThirdparty() {
    var html = new Array();
    html.push("<div class=\"distribPersonel dialog-warp-ajax\"");
    html.push("<form action=\"\" id=\"LoanWayAndTime\" >");
    html.push("<table class='dggui-table-info'>");
    html.push("<tbody>");
    html.push("<tr>");
    html.push("<th class='required'>户名：</th>");
    html.push("<td><input id=\"thirdpartyName_dialog\" type=\"text\" class=\"dggui-input \" maxlength='20'></td>");
    html.push("</tr>");
    html.push("<tr>");
    html.push("<th class='required'>卡号：</th>");
    html.push("<td><input id=\"thirdpartyNumber_dialog\" type=\"text\" class=\"dggui-input \" maxlength='20'></td>");
    html.push("</tr>");
    html.push("</tbody>");
    html.push("</table>");
    html.push("</form>");
    html.push("</div>");
    html = html.join('');
    dggui.dialog.open({
        content: html,
        title: "三方卡编辑",
        area: ['380px', '250px'],
        success: function () {
            $("#thirdpartyName_dialog").val($("#thirdpartyName").val());
            $("#thirdpartyNumber_dialog").val($("#thirdpartyNumber").val());
        },
        yes: function (index, layero) {
            var name = $("#thirdpartyName_dialog").val();
            var number = $("#thirdpartyNumber_dialog").val();
            if (!verifyEmpty($("#thirdpartyName_dialog"), "不能为空")) {
                return false;
            }
            if (!verifyEmpty($("#thirdpartyNumber_dialog"), "不能为空")) {
                return false;
            }
            if (!verifyBankCard($("#thirdpartyNumber_dialog"), "请输入正确的银行卡号")) {
                return false;
            }
            name = encodeHtml(name);
            number = encodeHtml(number);
            var txt = joinThirdparty(name, number);

            $("#thirdparty_name_and_number").html(txt);
            $("#thirdpartyNumber").val(number);
            $("#thirdpartyName").val(name);
            layer.close(index);
        }
    })
}

function joinThirdparty(name, number) {
    if (isEmpty(name) || isEmpty(number)) {
        return "<a href=\"javascript:;\" class=\"dggui-link\" onclick=\"getThirdparty()\">请编辑三方卡</a>";
    }
    return "<a href=\"javascript:;\" class=\"dggui-link\" onclick=\"getThirdparty()\">" + name + "/" + number + "</a>";
}


function formSubmit(url, obj) {
    console.log(obj);
    var form = $("<form></form>")
    form.attr("action", url);
    form.css('display', 'none');
    var b = false;
    for (var key in obj) {
        if (!isEmpty(obj[key])) {
            var input = $("<input type='hidden' name='" + key + "' />");
            input.attr('value', obj[key])
            form.append(input)
        }
        var isEmpyy = 'target' != key && (!isEmpty(obj[key]));
        if (isEmpyy) {
            b = true;
        }
    }
    if (!b) {
        dggui.dialog.errors('至少有一个筛选条件才能导出！');
        return;
    } else {
        form.appendTo("body");
        form.submit();
    }

}

//特定情况：有默认参数,排除obj中key包含在arr数组中的值
function formSubmit(url, obj, arr) {
    console.log(obj);
    var form = $("<form></form>")
    form.attr("action", url);
    form.css('display', 'none');
    var b = false;
    for (var key in obj) {
        if (!isEmpty(obj[key])) {
            var input = $("<input type='hidden' name='" + key + "' />");
            input.attr('value', obj[key])
            form.append(input)
        }
        var isEmpyy = false;
        if(null != arr){
            for(var i in arr) {
                var temp = arr[i];
                if(temp != key && (!isEmpty(obj[key]))){
                    isEmpyy =true
                }
            }
        }else{
            if(!isEmpty(obj[key])){
                isEmpyy =true
            }
        }
        if (isEmpyy) {
            b = true;
        }
    }
    if (!b) {
        dggui.dialog.errors('至少有一个筛选条件才能导出！');
        return;
    } else {
        form.appendTo("body");
        form.submit();
    }
}


//验证搜索框金额区间
function checkMoneySearch(moneyMin, moneyMax) {
    if (!isEmpty(moneyMin) && parseFloat(moneyMin) > 99999999999) {
        dggui.dialog.errors("金额不能超过99999999999");
        return false;
    }
    if (!isEmpty(moneyMin) && parseFloat(moneyMin) < 0) {
        dggui.dialog.errors("金额不能小于0");
        return false;
    }
    if (!isEmpty(moneyMax) && parseFloat(moneyMax) > 99999999999) {
        dggui.dialog.errors("金额不能超过99999999999");
        return false;
    }
    if (!isEmpty(moneyMax) && parseFloat(moneyMax) < 0) {
        dggui.dialog.errors("金额不能小于0");
        return false;
    }
    if (!isEmpty(moneyMax) && isEmpty(moneyMin)) {
        dggui.dialog.errors("请输入最小需求金额");
        return false;
    }
    if (isEmpty(moneyMax) && !isEmpty(moneyMin)) {
        dggui.dialog.errors("请输入最大需求金额");
        return false;
    }
    if (parseFloat(moneyMin) > parseFloat(moneyMax)) {
        dggui.dialog.errors("最小金额不能比最大金额大");
        return false;
    }
    return true;
}

function encodeHtml(s) {
    var REGX_HTML_ENCODE = /"|&|'|<|>|[\x00-\x20]|[\x7F-\xFF]|[\u0100-\u2700]/g;
    return (typeof s != "string") ? s :
        s.replace(REGX_HTML_ENCODE,
            function ($0) {
                var c = $0.charCodeAt(0), r = ["&#"];
                c = (c == 0x20) ? 0xA0 : c;
                r.push(c);
                r.push(";");
                return r.join("");
            });
}


/*----------------新增产品------------------------------*/
function addProduct(tableName, scOrderId) {
    var id = null;
    if (!isEmpty(tableName)) {
        //获取选中行对象
        var trs = getChecked("#" + tableName);
        if (trs.length > 1) {
            dggui.dialog.errors('只能选择一个订单')
            return;
        }
        if (trs.length == 0) {
            dggui.dialog.errors('请选择一条数据');
            return;
        }
        id = trs[0].id;
    } else {
        if (isEmpty(scOrderId)) {
            dggui.dialog.errors('订单ID不能为空');
            return;
        }
        id = scOrderId;
    }

    dggui.dialog.loading();
    $.ajax({
        type: 'POST',
        url: sysInfo.basePath + "/rzsc/processing_order/add_product_page.html",
        data: {
            scOrderId: id
        },
        success: function (resHtml) {
            if (resHtml.msg == null) {//后台没有异常
                addChannelIndex = dggui.dialog.open({
                    title: '新增产品',
                    content: resHtml,
                    area: '500px',

                    //弹框之后回调函数
                    success: function (layero, index) {
                        dgg.dialog.relocation(addChannelIndex);//弹框重新布局
                        dggui.dialog.loading('close')
                    },
                    //点击确定触发
                    yes: function (index, layero) {
                        var obj = new Object()
                        var id = $("#productOrderIdAdd").val();//当前主订单id
                        obj.id = id;
                        var typeCode = $("#typeCodeAdd .plug-in-code").val();//业务类型code
                        obj.typeCode = typeCode;
                        var productId = $("#productCodeAdd option:selected").val();//产品id
                        obj.productId = productId;
                        //var goodsId = $("#goodAttributeIdAdd option:selected").val();//商品属性id
                        //obj.goodsId = goodsId;
                        var channelId = $("#channelAdd option:selected").val();///渠道id
                        obj.channelId = channelId;
                        var channelName = $("#channelAdd option:selected").text();///渠道名称
                        obj.channelName = channelName;
                        var flowUserId = $("#addFlowUserIdAdd option:selected").val();///流程人员id
                        obj.flowUserId = flowUserId;
                        var channelSubBranch = $("#channelSubBranchAdd").val().trim();//支行
                        obj.channelSubBranch = channelSubBranch;
                        var amount = $("#moneyAdd").val();///金额
                        obj.amount = amount;
                        var remark = $("#remark").val();
                        obj.remark = remark;

                        if (isEmpty(id)) {
                            dggui.dialog.errors("当前主订单id缺失，请关闭弹窗再试");
                            return;
                        }
                        if (isEmpty(typeCode)) {
                            dggui.dialog.tip('请选择业务类型', $("#typeCodeAddTip"), {tipsMore: true});
                            return;
                        }
                        if (isEmpty(productId)) {
                            dggui.dialog.tip('请选择产品', $("#productCodeAddTip"), {tipsMore: true});
                            return;
                        }

                       /* if (isEmpty(goodsId)) {
                            dggui.dialog.tip('请选择商品属性', $("#goodAttributeIdAddTip"), {tipsMore: true});
                            return;
                        }*/

                        if (isEmpty(channelId)) {
                            dggui.dialog.tip('请选择渠道', $("#channelTip"), {tipsMore: true})
                            return;
                        }

                        if (isEmpty(flowUserId)) {
                            dggui.dialog.tip('请选择流程人员', $("#addFlowUserIdAddTip"), {tipsMore: true})
                            return;
                        }
                        if (!isEmpty(channelSubBranch) && channelSubBranch.length > 50) {
                            dggui.dialog.tip('支行信息最多50个字', $("#channelSubBranchAdd"), {tipsMore: true})
                            return;
                        }

                        //验证金额
                        if (isEmpty(amount)) {
                            dggui.dialog.tip('请输入金额', $("#moneyAdd"), {tipsMore: true})
                            return;
                        } else {
                            if (!isNumberTip($("#moneyAdd"), "请输入正确的数字", "定金不能超过99999999999")) {
                                return;
                            }
                        }
                        if (!verifyRemark($("#remark"), 0, 500, "请填写0-500字的备注信息")) {
                            return;
                        }

                        var paramsJson = JSON.stringify(obj);
                        dggui.dialog.confire('确认执行此操作？', '操作提示', function () {
                            dggui.dialog.loading();
                            $.ajax({
                                type: 'POST',
                                url: sysInfo.basePath + "/rzsc/processing_order/add_product.do",
                                data: {
                                    params: paramsJson
                                },
                                success: function (res) {
                                    dggui.dialog.loading('close');
                                    console.log(res);
                                    if (res.code == 0) {
                                        dggui.dialog.succeed(res.msg);
                                        dggui.dialog.close(index);//关闭弹框
                                        if (isEmpty(tableName)) {
                                            window.location.reload();
                                        } else {
                                            reloadTable("#" + tableName, "reload");//刷新分页
                                        }
                                    } else {
                                        dggui.dialog.errors(res.msg);
                                    }
                                }
                            });
                        })


                    }//yes end
                })//open end
            } else {
                dggui.dialog.errors(resHtml.msg);
                dggui.dialog.loading('close');
            }
        }//success end
    })//ajax end
};


/*----------------更换产品------------------------------*/
function changeProduct(tableName, scOrderId) {
    var id = null;
    if (!isEmpty(tableName)) {
        //获取选中行对象
        var trs = getChecked("#" + tableName);
        if (trs.length > 1) {
            dggui.dialog.errors('只能选择一个订单')
            return;
        }
        if (trs.length == 0) {
            dggui.dialog.errors('请选择一条数据');
            return;
        }
        id = trs[0].id;
    } else {
        if (isEmpty(scOrderId)) {
            dggui.dialog.errors('订单ID不能为空');
            return;
        }
        id = scOrderId;
    }
    dggui.dialog.loading();
    $.ajax({
        type: 'POST',
        url: sysInfo.basePath + "/rzsc/processing_order/change_product_page.html",
        data: {
            scOrderId: id
        },
        success: function (resHtml) {
            if (resHtml.msg == null) {//后台没有异常
                addChannelIndex = dggui.dialog.open({
                    title: '更换产品',
                    content: resHtml,
                    area: '500px',
                    //弹框之后回调函数
                    success: function (layero, index) {
                        dgg.dialog.relocation(addChannelIndex);//弹框重新布局
                        dggui.dialog.loading('close')
                    },
                    //点击确定触发
                    yes: function (index, layero) {
                        var obj = new Object()
                        var id = $("#productOrderIdAdd").val();//当前主订单id
                        obj.id = id;
                        var typeCode = $("#typeCodeAdd .plug-in-code").val();//业务类型code
                        obj.typeCode = typeCode;
                        var productId = $("#productCodeAdd option:selected").val();//产品id
                        obj.productId = productId;
                       /* var goodsId = $("#goodAttributeIdAdd option:selected").val();//商品属性id
                        obj.goodsId = goodsId;*/
                        var channelId = $("#channelAdd option:selected").val();///渠道id
                        obj.channelId = channelId;
                        var channelName = $("#channelAdd option:selected").text();///渠道名称
                        obj.channelName = channelName;
                        var channelSubBranch = $("#channelSubBranchAdd").val().trim();//支行
                        obj.channelSubBranch = channelSubBranch;
                        var remark = $("#remark").val();
                        obj.remark = remark;

                        if (isEmpty(id)) {
                            dggui.dialog.errors("当前主订单id缺失，请关闭弹窗再试");
                            return;
                        }
                        if (isEmpty(typeCode)) {
                            dggui.dialog.tip('请选择业务类型', $("#typeCodeAddTip"), {tipsMore: true});
                            return;
                        }
                        if (isEmpty(productId)) {
                            dggui.dialog.tip('请选择产品', $("#productCodeAddTip"), {tipsMore: true});
                            return;
                        }

                        /*if (isEmpty(goodsId)) {
                            dggui.dialog.tip('请选择商品属性', $("#goodAttributeIdAddTip"), {tipsMore: true});
                            return;
                        }*/

                        if (isEmpty(channelId)) {
                            dggui.dialog.tip('请选择渠道', $("#channelTip"), {tipsMore: true})
                            return;
                        }


                        if (!isEmpty(channelSubBranch) && channelSubBranch.length > 50) {
                            dggui.dialog.tip('支行信息最多50个字', $("#channelSubBranchAdd"), {tipsMore: true})
                            return;
                        }


                        if (!verifyRemark($("#remark"), 0, 500, "请填写0-500字的备注信息")) {
                            return;
                        }

                        var paramsJson = JSON.stringify(obj);
                        dggui.dialog.loading();
                        $.ajax({
                            type: 'POST',
                            url: sysInfo.basePath + "/rzsc/processing_order/change_product.do",
                            data: {
                                params: paramsJson
                            },
                            success: function (res) {
                                console.log(res);
                                if (res.code == 0) {
                                    dggui.dialog.loading('close');
                                    dggui.dialog.succeed(res.msg);
                                    dggui.dialog.close(index);//关闭弹框
                                    if (isEmpty(tableName)) {
                                        window.location.reload();
                                    } else {
                                        reloadTable("#" + tableName, "reload");//刷新分页
                                    }
                                } else {
                                    dggui.dialog.loading('close');
                                    dggui.dialog.errors(res.msg);
                                }
                            }
                        });
                    }//yes end
                })//open end
            } else {
                dggui.dialog.errors(resHtml.msg);
                dggui.dialog.loading('close');
            }
        }//success end
    })//ajax end
};


//批量接单
function receiveBatch(orderIds, tableName) {
    layer.confirm('确定接收吗？', {icon: 3, title: '提示'}, function (index) {
        dggui.dialog.loading();
        $.post(sysInfo.basePath + "/rzsc/processing_order/multi_receive_order.do", {orderIds: orderIds}, function (result) {
            dggui.dialog.loading('close');
            if (result.code == 0) {
                dggui.dialog.succeed('接收成功！');
                if (isEmpty(tableName)) {
                    window.location.reload();
                } else {
                    reloadTable("#" + tableName, "reload");//刷新分页
                }
            } else {
                dggui.dialog.errors(result.msg);
            }
        })
        layer.close(index);
    })
}

//单个接单
var channelIndex;

function receiveSingle(id, table) {
    dggui.dialog.loading();
    $.ajax({
        type: 'POST',
        async: false,
        url: sysInfo.basePath + "/rzsc/processing_order/receive_order.html",
        data: {
            id: id
        },
        success: function (resHtml) {
            if (resHtml.msg == null) {//后台没有异常
                channelIndex = dggui.dialog.open({
                    title: '接单',
                    content: resHtml,
                    area: '500px',
                    //弹框之后回调函数
                    success: function (layero, index) {
                        dgg.dialog.relocation(channelIndex);//弹框重新布局
                        dggui.dialog.loading('close')
                    },
                    //点击确定触发
                    yes: function (index, layero) {

                        var obj = new Object()
                        var id = $("#productOrderIdAdd").val();//当前主订单id
                        obj.id = id;
                        var typeCode = $("#typeCodeAdd .plug-in-code").val();//业务类型code
                        obj.typeCode = typeCode;
                        var productId = $("#productCodeAdd option:selected").val();//产品id
                        obj.productId = productId;
                      /*  var goodsId = $("#goodAttributeIdAdd option:selected").val();//商品属性id
                        obj.goodsId = goodsId;*/
                        var channelId = $("#channelAdd option:selected").val();///渠道id
                        obj.channelId = channelId;
                        var channelName = $("#channelAdd option:selected").text();///渠道名称
                        obj.channelName = channelName;
                        var channelSubBranch = $("#channelSubBranchAdd").val().trim();//支行
                        obj.channelSubBranch = channelSubBranch;

                        if (isEmpty(id)) {
                            dggui.dialog.errors("当前主订单id缺失，请关闭弹窗再试");
                            return;
                        }
                        if (isEmpty(typeCode)) {
                            dggui.dialog.tip('请选择业务类型', $("#typeCodeAddTip"), {tipsMore: true});
                            return;
                        }
                        if (isEmpty(productId)) {
                            dggui.dialog.tip('请选择产品', $("#productCodeAddTip"), {tipsMore: true});
                            return;
                        }
                       /* if (isEmpty(goodsId)) {
                            dggui.dialog.tip('请选择商品属性', $("#goodAttributeIdAddTip"), {tipsMore: true});
                            return;
                        }*/

                        if (isEmpty(channelId)) {
                            dggui.dialog.tip('请选择渠道', $("#channelTip"), {tipsMore: true})
                            return;
                        }

                        if (!isEmpty(channelSubBranch) && channelSubBranch.length > 50) {
                            dggui.dialog.tip('支行信息最多50个字', $("#channelSubBranchAdd"), {tipsMore: true})
                            return;
                        }


                        var paramsJson = JSON.stringify(obj);

                        dggui.dialog.loading();
                        $.ajax({
                            type: 'POST',
                            data: {params: paramsJson},
                            url: sysInfo.basePath + "/rzsc/processing_order/single_receive_order.do",
                            dataType: 'JSON',
                            success: function (data) {
                                dggui.dialog.loading('close');
                                if (data.code == 0) {//保存成功
                                    dggui.dialog.loading('close');
                                    dggui.dialog.succeed('接收成功！');
                                    layer.close(index);//关闭弹框
                                    reloadTable(table, "reload");
                                } else {
                                    dggui.dialog.loading('close');
                                    dggui.dialog.errors(data.msg);
                                }
                            },
                            error: function () {
                                dggui.dialog.loading('close')
                                dggui.dialog.errors("系统异常，请稍后再试");
                            }
                        });

                    }//yes end
                })//open end
            } else {
                dggui.dialog.errors(resHtml.msg);
                dggui.dialog.loading('close')
            }
        }//success end
    })
}

// 弹出权证工作录入
function cardWorkEntry(obj, type) {
    var orderId = "";
    var ids = getChecked(obj);
    if (ids.length < 1) {
        dggui.dialog.errors('请选择一条数据！');
        return;
    }
    if (ids.length > 1) {
        dggui.dialog.errors('只能选择一条数据！');
        return;
    }
    orderId = getIds(ids);
    if (!orderId) {
        dggui.dialog.errors('请选择一条数据！');
        return;
    }

    $.ajax({
        type: 'POST',
        url: sysInfo.basePath + "/order_detail/work_entry.html",
        data: {
            scOrderId: orderId,
            recordType: type
        },
        success: function (resHtml) {
            if (resHtml.msg == null) {//后台没有异常
                var title = "";
                if (type == 1) {
                    title = "权证员工作录入"
                } else if (type == 2) {
                    title = "资料员工作录入"
                } else if (type == 3) {
                    title = "评估人员工作录入"
                } else {
                    title = "驻点人员工作录入"
                }
                index = dggui.dialog.open({
                    title: title,
                    content: resHtml,
                    area: '1000px',
                    yes: function (index, layero) {
                        dggui.dialog.loading('close');
                        var recordType = $("#recordType").val();
                        var userId = $("#userId").val();
                        var scOrderId = $("#scOrderId").val();
                        var orgId = $("#orgId").val();
                        //序列化表格参数
                        var params = serializeTableArrary($('#workEntryTable'));
                        var verify = [];
                        //根据录入类型选择校验的字段
                        if (recordType == 1) {
                            verify = [
                                {
                                    "name": "handleTime",//验证字段名
                                    "type": [1],// 1 验证是否为空 2 是否有特殊字符  3 验证长度时候在指定范围 同时传mix和max参数 4 只能输入正整数
                                    "msg": "办理时日期"//提示信息
                                },
                                {
                                    "name": "handleArea",
                                    "type": [1],
                                    "msg": "办理区域"
                                },
                                {
                                    "name": "handleType",
                                    "type": [1],
                                    "msg": "办理类型"
                                },
                                {
                                    "name": "handlePlace",
                                    "type": [1],
                                    "mix": 1,
                                    "max": 50,
                                    "msg": "办理地点"
                                },
                                {
                                    "name": "remark",
                                    "type": [5],
                                    "mix": 0,
                                    "max": 120,
                                    "msg": "备注"
                                }
                            ]
                        } else if (recordType == 2) {
                            verify = [
                                {
                                    "name": "handleTime",
                                    "type": [1],
                                    "msg": "办理时日期"
                                },
                                {
                                    "name": "bank",
                                    "type": [1],
                                    "mix": 1,
                                    "max": 25,
                                    "msg": "银行"
                                },
                                {
                                    "name": "handleType",
                                    "type": [1],
                                    "msg": "办理类型"
                                },
                                {
                                    "name": "handleNum",
                                    "type": [1, 4],
                                    "mix": 1,
                                    "max": 10,
                                    "msg": "办理数量"
                                },
                                {
                                    "name": "remark",
                                    "type": [5],
                                    "mix": 0,
                                    "max": 120,
                                    "msg": "备注"
                                }
                            ]
                        } else if (recordType == 3) {
                            verify = [
                                {
                                    "name": "handleTime",
                                    "type": [1],
                                    "msg": "办理时日期"
                                },
                                {
                                    "name": "assessmentCompany",
                                    "type": [1],
                                    "mix": 1,
                                    "max": 120,
                                    "msg": "评估公司"
                                },
                                {
                                    "name": "bank",
                                    "type": [1],
                                    "mix": 1,
                                    "max": 25,
                                    "msg": "银行"
                                },
                                {
                                    "name": "remark",
                                    "type": [5],
                                    "mix": 0,
                                    "max": 120,
                                    "msg": "备注"
                                }
                            ]
                        } else if (recordType == 4) {
                            verify = [
                                {
                                    "name": "loanTime",
                                    "type": [1],
                                    "msg": "放款日期"
                                },
                                {
                                    "name": "loanMoney",
                                    "type": [6],
                                    "mix": 1,
                                    "max": 20,
                                    "msg": "放款金额"
                                },
                                {
                                    "name": "productName",
                                    "type": [1],
                                    "mix": 1,
                                    "max": 120,
                                    "msg": "产品名称"
                                },
                                {
                                    "name": "channelName",
                                    "type": [1],
                                    "mix": 1,
                                    "max": 25,
                                    "msg": "渠道"
                                },
                                {
                                    "name": "remark",
                                    "type": [5],
                                    "mix": 0,
                                    "max": 120,
                                    "msg": "备注"
                                }
                            ]
                        }
                        for (var i = 0; i < params.length; i++) {
                            if (!verifyObject(verify, params[i])) {
                                return false;
                            }
                        }
                        $.ajax({
                            url: sysInfo.basePath + "/order_detail/work_entry_add.do",
                            data: {
                                recordType: recordType,
                                userId: userId,
                                scOrderId: scOrderId,
                                orgId: orgId,
                                pofwlJson: JSON.stringify(params)
                            },
                            success: function (res) {
                                dggui.dialog.loading('close');
                                if (res.code == 0) {
                                    dggui.dialog.succeed("保存成功");
                                    layer.close(index);
                                    reloadTable(obj, "reload");
                                } else {
                                    dggui.dialog.errors(res.msg);
                                }
                            }
                        });

                    }
                })
            } else {
                dggui.dialog.errors(resHtml.msg);
                dggui.dialog.loading('close');
            }
        }
    })//ajax end
}